//
//  SZZMainViewController.swift
//  SZZweibo
//
//  Created by 申壮壮 on 16/8/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SZZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = SZZTabBar()
        
        tabBar.szzDelegate = self
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(SZZHomeViewController(), imgName: "tabbar_home", title: "首页")
        // 消息
        addChildViewController(SZZMessageViewController(), imgName: "tabbar_message_center", title: "消息")
        // 发现
        addChildViewController(SZZDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
        // 我
        addChildViewController(SZZProfileViewController(), imgName: "tabbar_profile", title: "我")
        
  
    }
    func addChildViewController(vc: UIViewController, imgName: String, title: String){
        
        vc.title = title
        // 设置title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)
        // AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}


extension SZZMainViewController:SZZTabBarDelegate{
    
    
    func tabBarButtonClick() {
        print("被点了")
    }
    
}
    
    


    

